package com.soup.faker.interceptor;

import com.soup.faker.api.Generator;
import com.soup.faker.api.Interceptor;
import com.soup.faker.wrapper.ValueWrapper;

import java.util.ArrayList;
import java.util.List;

public class MementoInterceptor<T> implements Interceptor<T> {

    private final List<T> memento;
    private final int maxSize;

    public MementoInterceptor() {
        this(Integer.MAX_VALUE);
    }

    public MementoInterceptor(int maxSize) {
        this.memento = new ArrayList<>();
        this.maxSize = maxSize;
    }

    public MementoInterceptor(List<T> list) {
        this(list, Integer.MAX_VALUE);
    }

    public MementoInterceptor(List<T> list, int maxSize) {
        this.memento = list;
        this.maxSize = maxSize;
    }

    @Override
    public void before(ValueWrapper<T> valueWrapper) {

    }

    @Override
    public void after(ValueWrapper<T> valueWrapper, Generator<T> generator) {
        if(memento.size() == maxSize) {
            memento.remove(0);
        }
        memento.add(valueWrapper.get());
    }

    @Override
    public void throwing(ValueWrapper<T> valueWrapper, Generator<T> generator, Exception ex) {

    }

}
